export default function (option = {}) {
  let {
    objName = 'search',
    startDateField = 'startTime',
    endDateField = 'endTime',
    startOptionName = 'startDateOption',
    endOptionName = 'endDateOption'
  } = option;
  return {
    data() {
      let vueData = {};
      vueData[startOptionName] = {
        disabledDate: time => {
          return this.dateLimit(time, 'startDate');
        }
      };
      vueData[endOptionName] = {
        disabledDate: time => {
          return this.dateLimit(time, 'endDate');
        }
      };
      return vueData;
    },
    methods: {
      dateLimit(time, field) {
        let obj = this[objName];
        if (field === 'startDate') {
          let endDate = obj[endDateField];
          if (endDate !== null) {
            return this.$moment(time).isAfter(endDate, 'day');
          }
        } else if (field === 'endDate') {
          let startDate = obj[startDateField];
          if (startDate !== null) {
            return this.$moment(time).isBefore(startDate, 'day');
          }
        }
        return false;
      }
    }
  };
}
